<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="iwpl.project.dao.AccountsDAO"%>
<%@page import="iwpl.project.entities.Accounts"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//String t = (String)session.getAttribute("Manage_Account");
//if(t!="active")
	///{response.sendRedirect("index.jsp");}
List<Accounts> list1 =(List<Accounts>)session.getAttribute("lSearch");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<center>

<html>
  <head>
    <base href="<%=basePath%>">
    <script type="text/javascript">
			function Confirm(id) 
			{
			
				var text = confirm("Are you sure ?");
				
				if (text == true)
				{
					//alert("Okey, Deleted !!!");
					location.href = "./servlet/Control_Account?id="+id+"&action=Delete";
				}
				else 
				{
					alert("What ever !!!");
				}
			}
		</script>
    <title>Manage Account</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cakljklkli  mn  che">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
        .style1
        {
            width: 100%;
            height: 142px;
        }
        .style2
        {
            width: 55px;
        }
    </style>
  </head>
  
  <body>
  <form name="frmManageAccount" action="./servlet/Control_Account" method="get">
  <table cellpadding="0" cellspacing="0" >
            <tr>
                <td>
                   
                               <table align="center">
	                               <tr>
										<td colspan="3">
											<%
												if(request.getParameter("message")!=null)
												{
													String a = request.getParameter("message").toString();
													out.print(a);
												}
											 %>
										</td>
									</tr>
				     				<tr>
				     					<td colspan ="3" align="center">
				     						Manage Account
				     					</td>
				     				</tr>
				     				<tr>
				     					<td>
				     					UserName:
				     					</td>
				     					<td>
				     						<input type="text" name="empName" />
				     						<input type="hidden" name="action" value="search" >
				     					</td>
				     					<td>
				     						
				     						
				     					</td>
				     				</tr>
				     				<tr>
		     							<td>
		     								<a href="Insert_Account.jsp">Insert</a>
		     							</td>
		     						</tr>
				     				<tr>
				     					<td colspan="3">
				     						<table>
				     						
				     							<tr bgcolor="5f9ff5">
					     							<td>
					     								STT
					     							</td>
				     								<td>
				     									EmployeeName
				     								</td>
				     								<td>
				     									UserName
				     								</td>
				     								<td>
				     									Role
				     								</td>
				     								<td>
				     									Status
				     								</td>
				     								<td>
				     									Edit
				     								</td>
				     								<td>
				     									Delete
				     								</td>
				     							</tr>
				     							<%
													AccountsDAO dao = new AccountsDAO();
													//List<Accounts> list = null;
														
							
													String tam = request.getParameter("empName");
													//if(t != null) {
														//list1 = dao.findByUserName(t);
													//} else {
													//	list1 = dao.findAll();
													//}	
							
													if(list1==null)
														{
															list1 =dao.findAll();
														}
							
													int i = 0;
							
													for (Iterator<Accounts> it = list1.iterator(); it.hasNext();) {
														Accounts acc = (Accounts) it.next();
														i++;
							
														if (i % 2 != 0) {
															out.println("<tr bgcolor=\"#CCFFFF\"><td>");
														} else {
															out.println("<tr bgcolor=\"#99CCCC\"><td>");
														}
														out.println(i + "</td>");
														out.println("<td>" + acc.getEmployees().getFullName()+"</td>");
														out.println("<td>" + acc.getUserName() + "</td>");
														out.println("<td>" + acc.getRoles().getRoleName()  + "</td>");
														out.println("<td>" + acc.getRoles().getActive()  + "</td>");
							
														//	out.println("<td>" + apart.getValue() + "</td>");
														//out.println("<td>" + rsq.getString("CountID") + "</td></tr>");
														//out.println("<td>" + rs.getString("Status") + "</td></tr>");
														out.println("<td><a href="
																+ "/DepartmentManage/Update_Account.jsp?aid="
																+ acc.getId()+ " /><img src="
																+ "./images/Edit.jpg" + " /></td>");
														/*out.println("<td><a href=" + "./servlet/myservlet?delete="
																+ rs.getString("CategoryID") + " /><img src="
																+ "./Pics/Delete.jpg" + " /></td></tr>");*/
														//out.println("<td><img src=\"./Pics/Delete.jpg\" onclick =\"Confirm()\"/></td></tr>");
														out.println("<td><a href=javascript:Confirm('" + acc.getId()
																+ "') /><img src=" + "./images/Delete.jpg"
																+ " /></td></tr>");
													}
												%>  							
				     						</table>
				     					</td>
				     				</tr>
				     			</table>
                                
                          
                </td>
            </tr>
        </table>
  </form>
  </body>
</html>
</center>